package aps

import cn.hutool.json.JSONUtil
import glory.xxd.Utils

/**
 * 执行结束作业
 */
class EndProcessController {

    def commentService

    def index() {

        try {
            def EqpId = params.EqpId ?: ""
            def LotId = params.LotId ?: ""
            def DoneQty = params.DoneQty ?: ''
            def TotalQty = params.TotalQty ?: ''
            def OPID = params.OPID ?: ''
            String logUUID = Utils.getUUID();

            def header = [MESSAGENAME: "EndProcess", TRANSACTIONID: logUUID, USERNAME: "EAP"]
            header = "<Header>${Utils.getXmlByJSONHtml(header)}</Header>"

            def InputDataList =params.InputDataList
            def isJsonArray = JSONUtil.isJsonArray(InputDataList)

            if (isJsonArray) {
                InputDataList = Utils.getXmlByJSONArray(InputDataList)
            } else {
                InputDataList = Utils.getXmlByJSONHtml(InputDataList)
            }

            def body = [EqpId: EqpId, LotId: LotId, DoneQty: DoneQty,TotalQty:TotalQty, OPID: OPID,INPUTDATALIST:InputDataList]

            body = "<Body>${Utils.getXmlByJSONHtml(body)}</Body>"
            def xml = "<Request>${header}${body}</Request>"
            def json = commentService.getJsonByObjectForTopic2Queue(logUUID, xml)
            //println xml
            render json
        } catch (Exception e) {
            e.printStackTrace()
        }
    }
}